package com.biometric.core.retriever

import android.app.Application

object AppContext {
    private var appContext :Application

    init {
        val activityThreadClass = Class.forName("android.app.ActivityThread")
        val thread: Any = getActivityThread()
        val app = activityThreadClass.getMethod("getApplication").invoke(thread)
        appContext = app as Application
    }

    private fun getActivityThread(): Any {
        val activityThreadClass = Class.forName("android.app.ActivityThread")
        val sCurrentActivityThreadField =
            activityThreadClass.getDeclaredField("sCurrentActivityThread")
        sCurrentActivityThreadField.isAccessible = true
        return sCurrentActivityThreadField.get(null)!!
    }

    @JvmStatic
    fun get(): Application {
        return appContext
    }
}